package com.aiti.lulian.controller.newCard;

import cn.hutool.core.exceptions.ExceptionUtil;
import com.aiti.base.core.exception.BusinessException;
import com.aiti.base.core.utils.message.Message;
import com.aiti.lulian.dto.newCard.CardEnterpriseCooperationAddParamDto;
import com.aiti.lulian.dto.newCard.EnterpriseCooperationQueryDto;
import com.aiti.lulian.dto.newCard.UpdateWechatGroupParamDto;
import com.aiti.lulian.service.newCard.CardEnterpriseCooperationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * description:
 * auth fcb
 * date 2025-08-20 14:46
 **/
@RestController
@RequestMapping("/new-card/card-enterprise-cooperation")
@Slf4j
@Api(tags = "合作大厅接口")
public class CardEnterpriseCooperationController {

    @Autowired
    private CardEnterpriseCooperationService cardEnterpriseCooperationService;

    @GetMapping("/enterprise-info")
    @ApiOperation("根据企业名片id查询企业名称")
    public Message getEnterpriseInfoByEnterpriseCardId(@RequestParam("enterpriseCardId") String enterpriseCardId) {
        try{
            return Message.success(cardEnterpriseCooperationService.getEnterpriseInfoByEnterpriseCardId(enterpriseCardId));
        }catch (Exception e) {
            if(e instanceof BusinessException) {
                return Message.fail(e.getMessage());
            }
            log.error("查询异常：{}", ExceptionUtil.stacktraceToString(e));
            return Message.fail("查询异常");
        }
    }

    @PostMapping("/add-enterprise-cooperation")
    @ApiOperation("添加合作大厅")
    public Message addEnterpriseCooperation(@RequestBody CardEnterpriseCooperationAddParamDto paramDto) {
        try{
            cardEnterpriseCooperationService.addEnterpriseCooperation(paramDto);
            return Message.success();
        }catch (Exception e) {
            if(e instanceof BusinessException) {
                return Message.fail(e.getMessage());
            }
            log.error("添加合作异常：{}", ExceptionUtil.stacktraceToString(e));
            return Message.fail("操作异常");
        }
    }

    @PostMapping("/enterprise-cooperation-list")
    @ApiOperation("查询合作大厅合作列表")
    public Message queryEnterpriseCooperationList(@RequestBody EnterpriseCooperationQueryDto queryDto) {
        try{
            return Message.success(cardEnterpriseCooperationService.queryEnterpriseCooperationList(queryDto));
        }catch (Exception e) {
            if(e instanceof BusinessException) {
                return Message.fail(e.getMessage());
            }
            log.error("查询异常：{}", ExceptionUtil.stacktraceToString(e));
            return Message.fail("查询异常");
        }
    }

    @GetMapping("/enterprise-cooperation-info")
    @ApiOperation("查询合作大厅合作详情")
    public Message getEnterpriseCooperationById(@RequestParam("enterpriseCooperationId") String enterpriseCooperationId) {
        try{
            return Message.success(cardEnterpriseCooperationService.getEnterpriseCooperationById(enterpriseCooperationId));
        }catch (Exception e) {
            if(e instanceof BusinessException) {
                return Message.fail(e.getMessage());
            }
            log.error("查询异常：{}", ExceptionUtil.stacktraceToString(e));
            return Message.fail("查询异常");
        }
    }

    @GetMapping("/inviter-rank-list")
    @ApiOperation("查询邀请榜")
    public Message queryInviterRankList(@RequestParam("circleId") String circleId) {
        try{
            return Message.success(cardEnterpriseCooperationService.queryInviterRankList(circleId));
        }catch (Exception e) {
            if(e instanceof BusinessException) {
                return Message.fail(e.getMessage());
            }
            log.error("查询异常：{}", ExceptionUtil.stacktraceToString(e));
            return Message.fail("查询异常");
        }
    }

    @GetMapping("/circle-admin-info")
    @ApiOperation("查询圈子管理员信息")
    public Message queryCircleAdminInfo(@RequestParam("circleId") String circleId, @RequestParam("enterpriseCardId") String enterpriseCardId) {
        try{
            return Message.success(cardEnterpriseCooperationService.queryCircleAdminInfo(circleId, enterpriseCardId));
        }catch (Exception e) {
            if(e instanceof BusinessException) {
                return Message.fail(e.getMessage());
            }
            log.error("查询异常：{}", ExceptionUtil.stacktraceToString(e));
            return Message.fail("查询异常");
        }
    }

    @PostMapping("/update-circle-wechat-group-url")
    @ApiOperation("更新圈子微信群链接")
    public Message updateCircleWechatGroupUrl(@RequestBody UpdateWechatGroupParamDto paramDto) {
        try{
            cardEnterpriseCooperationService.updateCircleWechatGroupUrl(paramDto);
            return Message.success();
        }catch (Exception e) {
            if(e instanceof BusinessException) {
                return Message.fail(e.getMessage());
            }
            log.error("更新异常：{}", ExceptionUtil.stacktraceToString(e));
            return Message.fail("操作异常");
        }
    }

}
